Skip to content

plugins: ensure to log the offending plugin on instantiation failure #5739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

wisp3rwind
Copy link
Member

@wisp3rwind wisp3rwind commented Apr 17, 2025

Came up in #5701 (comment) where an error can't easily be traced back to a plugin.

(Draft because I want to avoid creating merge conflicts for #5701 before that is merged, and because I might a few additional improvements here.)

Copy link

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@wisp3rwind wisp3rwind force-pushed the plugin-traceback branch 5 times, most recently from bde4397 to 2129eb4 Compare April 20, 2025 08:43
@wisp3rwind wisp3rwind marked this pull request as ready for review April 20, 2025 09:01
Copy link

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@wisp3rwind
Copy link
Member Author

This should be ready to go now; it's easiest to review commit-by-commit.

minimize how much code is wrapped in a given try...except statement
…roken error handling

from a quick test, it appears that the old code shouldn't even be working
anymore due to additional quotes in exc.args[0]
also remove a unnecessary check before adding to a set
without an argument (i.e. the default `names=()`), this was a no-op
actual plugin loading is triggered by tests, or by the ui code

-> Turns out it's not an actual no-op in our testing code due to
   patching with attaching some side-effects to load_plugins...
   This is fixed up in the next commit.
Instead of the first call to find_plugins(). This could change behavior
slightly, since plugin load (and errors that happen in the process) could
occur earlier now. But:

- I'd argue this is better anyway, since plugin load errors now happen
  in the initial call to load_plugins() instead of somewhere in the
  middle of the first operation that uses plugins.
- In our ui code, both happen immediately after each other anyway:
  ui._setup calls
  	1) ui._load_plugins -> plugins.load_plugins
	2) plugins.types, plugins.named_queries, ...
- better error handling (includes restoring some unintended changes)
- cleanup of some traces of the previous architecture of the plugin
  loader
@wisp3rwind
Copy link
Member Author

Should be good to go, but I'll rebase on #5841 once its merged.

Note that this isn't quite what the title says anymore: Logging wasn't as incomplete as I thought in the context of #5701. Thus, this PR only slightly improves logging, notably by fixing the "not found" error case (detection of which was quite hacky before, and in fact broken), and by logging the fully-qualified path to offending plugin classes.

Additionally, the PR refactors plugin loading, reducing nesting of the code, and actually instantiating plugins in load_plugins instead of find_plugins (which makes more sense conceptually, and the laziness in the former approach was irrelevant or even detrimental in practice).

Comment on lines +389 to +394
if cls in _instances:
log.debug(
"repeated initialization of plugin class {}.{}",
cls.__module__,
cls.__qualname__,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if cls in _instances:
log.debug(
"repeated initialization of plugin class {}.{}",
cls.__module__,
cls.__qualname__,
)

Let's remove this check and ensure uniqueness with

for name in set(names):
...

on line 357.

Copy link
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I've re-run the build and added a small comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants